import org.grails.plugins.lookups.Lookup
import org.grails.plugins.lookups.LookupValue
class BootStrap {
     def authenticateService

     def init = { servletContext ->

        System.out = new  PrintStream(System.out, true, "gbk")
        // 地区
        def area = Lookup.findByRealm('area') 
        area = area?area:new Lookup(realm:"area",
                                        codeType:"string",
                                        codeMinimum:"",
                                        codeMaximum:"", 
                                        valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save();

        ['高新','莲湖','新城','碑林','雁塔','未央','霸桥','阉良','临潼','长安','其他'].eachWithIndex{it, index ->
         new LookupValue(lookup: area ,
                                        code: it,
                                        value: it, 
                                        sequencer : index ,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }
        // 专业
        def major = Lookup.findByRealm('major') 
        major = major?major:new Lookup(realm:"major",
                                        codeType:"string",
                                        codeMinimum:"",
                                        codeMaximum:"", 
                                        valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save();

      
        ['请选择','数学','体育运动','舞蹈','理科','机电一体化','心理学','服装设计','应用心理学','土木工程','幼师','城市规划','科学教育','公共事业管理','学前教育','制药工程','音乐教育专业','汉语言文学','自动化','园林','电子信息','工业工程','会计','交通运输','艺术设计','海洋渔业','法律','汉语言文学','材料成型','生物科学','新闻学','日语','财务会计','美术系','市场营销','通信工程','应用化学','软件工程','工商管理类','工业设计','旅游管理','物理','电子商务','韩语','绘画','国际贸易','中文','管理类','物流管理','控制系自动化','历史学','计算机','英语','其他专业'].eachWithIndex{it, index ->
         new LookupValue(lookup: major ,
                                        code: it,
                                        value: it, 
                                        sequencer : index ,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }

        // 学历
        def education = Lookup.findByRealm('education') 
        education = education?education:new Lookup(realm:"education",
                                        codeType:"string",
                                        codeMinimum:"",
                                        codeMaximum:"", 
                                        valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save();

      
        ['博士后','博士','研究生','本科','专科','高中'].eachWithIndex{it, index ->
         new LookupValue(lookup: education ,
                                        code: it,
                                        value: it, 
                                        sequencer : index ,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }

        // 现在教师情况
        def postion = Lookup.findByRealm('postion') 
        postion = postion?postion:new Lookup(realm:"postion",
                                        codeType:"string",
                                        codeMinimum:"",
                                        codeMaximum:"", 
                                        valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save();

      
        ['在校大学生(研究生)','专职教师(在职、退休)','其他(工作人员、海归人员等)'].eachWithIndex{it, index ->
         new LookupValue(lookup: postion ,
                                        code: it,
                                        value: it, 
                                        sequencer : index ,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }
         // 授课方式
        def teacherType = Lookup.findByRealm('teacherType') 
        teacherType = teacherType?teacherType:new Lookup(realm:"teacherType",
                                        codeType:"string",
                                        codeMinimum:"",
                                        codeMaximum:"", 
                                        valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save();

      
        ['学生上门','教师上门','网上辅导','第三方场地','协商','不限'].eachWithIndex{it, index ->
         new LookupValue(lookup: teacherType ,
                                        code: it,
                                        value: it, 
                                        sequencer : index ,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }

        // 教学科目
        def courses = Lookup.findByRealm('courses') 
        courses = courses?courses:new Lookup(realm:"courses",
                                        codeType:"string",
                                        codeMinimum:"",
                                        codeMaximum:"", 
                                        valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save();

      
        ['语文','数学','英语','物理','化学','生物','历史','地理','计算机','日语','作文'].eachWithIndex{it, index ->
         new LookupValue(lookup: courses ,
                                        code: it,
                                        value: it, 
                                        sequencer : index ,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }

        ['ROLE_TEACHER':'老师',
        'ROLE_STUDENT':'学生', 
        'ROLE_ADMIN':'系统管理员'].each{ entry ->
         new Role(authority:entry.key,
                        description:entry.value).save()
        }

        if (!User.findByUsername('admin')) {
            def person = new User(username: 'admin' , realname:'管理员',enabled : true)
            person.birthday = new Date()
            person.passwd = authenticateService.encodePassword('1qazxsw2')
            person.save()
            Role.findByAuthority("ROLE_ADMIN").addToPeople(person) 
        }
     }
     def destroy = {
     }
} 